package com.zhenai.rocyuan.modules.myannotation.d1;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Test;



public class AnnotationTest {

	@Test
	public void testClass() {
		Game game = new Game();
		System.out.println( game.getClass() == Game.class );
		System.out.println( game.getClass().equals(Game.class ));

	}
	
	
	public static void main(String[] args) throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		
		Game game = new Game();
		
		Field[] fieids = game.getClass().getDeclaredFields();
		
		for(Field field : fieids){
			Default default1 = field.getAnnotation(Default.class);
			if(default1 != null){
				PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), Game.class);
				Method setMethod = propertyDescriptor.getWriteMethod();
				if(setMethod !=null){
					String value = default1.value();
					field.setAccessible(true);
					setMethod.invoke(game, value);
				}
				
			}
			
			
		}
		
		System.out.println(game.toString());
		
	}
}
